//snipersentry.txt
//By Lazarus:
//This is for the golum sentries in a particular puzzle.
//If sentry can see you, it first takes aim.
//If it can still see you next turn, it kills you.
//It should not be used in any other situation, unless you want a creature to kill you in a single shot.

begincreaturescript;

variables;
short ox,oy,mx,my,i,px,py,target,tick;
body;

beginstate init_state;
	tick = -1;
	set_mobility(ME,0);
break;

beginstate start_state;
		target = 0;
		while(char_ok(target) == 0) 
			{ target = target + 1; }
		
		if(tick >= 0)
			if((get_current_tick() - tick) >= 1)
				if(can_see_loc(char_loc_x(target),char_loc_y(target)) == 0) 
				{	message_dialog("You get out of the way just in time. A beam strikes where you were just standing.","");
					mx = my_loc_x();
					my = my_loc_y();
					set_character_pose(ME,1);
					force_instant_terrain_redraw();
					put_straight_zap((mx),(my),(ox),(oy),5);
					put_effect_on_space((ox),(oy),1,5,0);
					run_animation_sound(51);
					set_character_pose(Me,2);
					force_instant_terrain_redraw();
					tick = -1;
					end(); }

		if(can_see_loc(char_loc_x(target),char_loc_y(target)))
		{
		if(tick >= 0)
			if((get_current_tick() - tick) >= 1) 
			{	px = char_loc_x(target);
				py = char_loc_y(target);
				mx = my_loc_x();
				my = my_loc_y();
				set_character_pose(ME,1);
				force_instant_terrain_redraw();
				put_straight_zap((mx),(my),(px),(py),5);
				put_effect_on_char((target),1,5,0);
				run_animation_sound(51);
				kill_char((target),2,0);
				message_dialog("The sniper takes aim and guns you down. You should do a better job hiding next time.","");
				set_character_pose(Me,2);
				force_instant_terrain_redraw();
				set_total_visibility(0);
				tick = 0;
				end_combat_turn();
				end(); }

			if(tick == -1)
			{	tick = get_current_tick();
				message_dialog("The sniper spots you and takes aim. If you don't move quickly you're going to get wasted.","");
				ox = char_loc_x(target);
				oy = char_loc_y(target);
				end();	
				end_combat_turn(); }
}
break;
beginstate dead_state;
break;

beginstate talking_state;
print_str("It doesn't respond.");
break;

